# ImageMagick 安装和配置脚本

Write-Host "========================================"
Write-Host "ImageMagick 安装和配置指南"
Write-Host "========================================"
Write-Host ""

# 检查是否已安装
Write-Host "1. 检查 ImageMagick 是否已安装..."
$magickPath = Get-Command magick -ErrorAction SilentlyContinue
if ($magickPath) {
    Write-Host "✅ 已找到 ImageMagick: $($magickPath.Source)" -ForegroundColor Green
    Write-Host "   版本信息:"
    & magick -version | Select-Object -First 3
} else {
    Write-Host "❌ 未找到 ImageMagick" -ForegroundColor Red
    Write-Host ""
    Write-Host "2. 安装步骤:" -ForegroundColor Yellow
    Write-Host "   a) 访问: https://imagemagick.org/script/download.php#windows"
    Write-Host "   b) 下载 Windows 版本 (推荐: ImageMagick-7.x.x-Q16-HDRI-x64-dll.exe)"
    Write-Host "   c) 运行安装程序，安装时务必选择:"
    Write-Host "      - 'Install legacy utilities (e.g. convert)'"
    Write-Host "      - 'Add application directory to your system path'"
    Write-Host "   d) 安装完成后，重新运行此脚本验证"
    Write-Host ""
    Write-Host "3. 手动配置路径（如果 ImageMagick 已安装但未在 PATH 中）:" -ForegroundColor Yellow
    Write-Host "   在 PowerShell 中运行:"
    Write-Host "   `$env:IMAGEMAGICK_BINARY = 'C:\Program Files\ImageMagick-7.x.x-Q16-HDRI\magick.exe'"
    Write-Host "   或添加到系统环境变量中"
    Write-Host ""
}

Write-Host ""
Write-Host "4. 测试配置:" -ForegroundColor Yellow
Write-Host "   运行: python -m mm_story_agent.imagemagick_config"
Write-Host ""

# 测试 Python 配置
Write-Host "5. 测试 Python 中的 ImageMagick 配置..."
try {
    python -c "from mm_story_agent.imagemagick_config import configure_imagemagick, test_imagemagick; import sys; sys.exit(0 if (configure_imagemagick() and test_imagemagick()) else 1)" 2>&1
    if ($LASTEXITCODE -eq 0) {
        Write-Host "✅ Python 配置成功！" -ForegroundColor Green
    } else {
        Write-Host "❌ Python 配置失败，请检查 ImageMagick 安装" -ForegroundColor Red
    }
} catch {
    Write-Host "⚠️  无法测试 Python 配置: $_" -ForegroundColor Yellow
}

Write-Host ""
Write-Host "========================================"
